<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>字数统计</title>
    <meta name="viewport"
          content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
    <style>
        body,div,input,textarea{
            margin: 0;
            padding: 0;
        }
        input,textarea{
            -webkit-appearance: none;
        }
        a{
            text-decoration: none;
        }
        .page{
            padding: 0 10px;
        }
        .text{
            height: 100px;
            margin: 20px auto;
            outline: 1px solid #f60;
            position: relative;
        }
        .textarea{
            width: 100%;    
            height: 100%;   
            resize: none;
            border: none;
            padding: 10px;
            box-sizing: border-box;
            outline: none;
            font-size: 20px;
        }
        .count{
            width: 100%;    
            height: 50px;
            border: none;
            background-color: #f60;
            color: #fff;
            font-size: 20px;    
            border-radius: 2px;
        }
        @font-face {
            font-family: 'iconfont';  /* project id："21714" */
            src: url('//at.alicdn.com/t/font_1447569455_5998726.eot');
            src: url('//at.alicdn.com/t/font_1447569455_5998726.eot?#iefix') format('embedded-opentype'),
            url('//at.alicdn.com/t/font_1447569455_5998726.woff') format('woff'),
            url('//at.alicdn.com/t/font_1447569455_5998726.ttf') format('truetype'),
            url('//at.alicdn.com/t/font_1447569455_5998726.svg#iconfont') format('svg');
        }
        .icon{
            font-family:"iconfont" !important;
            font-size:16px;
            font-style:normal;
            -webkit-font-smoothing: antialiased;
            -webkit-text-stroke-width: 0.2px;
            -moz-osx-font-smoothing: grayscale;
        }
        .del-icon{
            position: absolute;
            right: 10px;
            bottom: 10px;
            color: #f60;
        }
    </style>
</head>
<body>
<div class="page">  
    <div class="text">
        <textarea class="textarea"></textarea>
        <a id="J_del" href="javascript:" class="del-icon icon">&#xe60d;</a>
    </div>
    <input type="button" class="count" value="统计字数">
</div>
<script src="http://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
<script>
    var len,
        str;
    $('.textarea').on('input propertychange',function (){
        str = $('.textarea').val().replace(/\s+/g,'');
        len = str.length;
        $('.count').val('总共有 '+len+' 个字');
    });

    //删除文字
    $('.textarea').on('click touchend',function (e){
        var inputPositionX = $(this).offset().left;
        var inputWidth = $(this).outerWidth();
        console.log(inputPositionX,inputWidth);
        var eventPositionX = inputPositionX+inputWidth;
        console.log(e.originalEvent.pageX);
        if(e.originalEvent.pageX > eventPositionX - 50 && e.originalEvent.pageX < eventPositionX){
            $('.textarea').val('');
            $('.count').val('统计字数');
        }        
    });
</script>
</body>
</html>